<template>
  <a-spin :spinning="confirmLoading">
    <j-form-container :disabled="formDisabled">
      <a-form-model ref="form" :model="model" :rules="validatorRules" slot="detail">
        <a-row>
          <a-col :span="24">
            <a-form-model-item label="数据日期" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="sjrq">
              <j-date placeholder="请选择数据日期" v-model="model.sjrq"  style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="资管计划名称" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="zgjhmc">
              <a-input v-model="model.zgjhmc" placeholder="请输入资管计划名称"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="资产类别" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="zclb">
              <j-tree-select
                ref="treeSelect"
                placeholder="请选择资产类别"
                v-model="model.zclb"
                dict="llbb_param_config,name,code"
                pidValue="1486577101990047746"
                hasChildField="has_child"
              />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="资产名称" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="zcmc">
              <a-input v-model="model.zcmc" placeholder="请输入资产名称"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="资产编码（或合同号）" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="zcbh">
              <a-input v-model="model.zcbh" placeholder="请输入资产编码（或合同号）"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="资产原值" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="zcyz">
              <a-input-number v-model="model.zcyz" placeholder="请输入资产原值" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="资产净值（或资产估值）" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="zcjz">
              <a-input-number v-model="model.zcjz" placeholder="请输入资产净值（或资产估值）" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="备注" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="bz">
              <a-input v-model="model.bz" placeholder="请输入备注"  ></a-input>
            </a-form-model-item>
          </a-col>
          <!-- <a-col :span="24">
            <a-form-model-item label="法人标识" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="bankNoCd">
              <a-input v-model="model.bankNoCd" placeholder="请输入法人标识"  ></a-input>
            </a-form-model-item>
          </a-col> -->
          <!-- <a-col :span="24">
            <a-form-model-item label="数据来源：0-在线录入;1-批量导入;2-跑批录入;3-跑批修改;" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="dataSources">
              <a-input v-model="model.dataSources" placeholder="请输入数据来源：0-在线录入;1-批量导入;2-跑批录入;3-跑批修改;"  ></a-input>
            </a-form-model-item>
          </a-col> -->
          <!-- <a-col :span="24">
            <a-form-model-item label="数据当前片数" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="sjdqps">
              <a-input-number v-model="model.sjdqps" placeholder="请输入数据当前片数" style="width: 100%" />
            </a-form-model-item>
          </a-col> -->
          <a-col :span="24">
            <a-form-model-item label="内部机构号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="nbjgh">
              <Mechanism v-model="model.nbjgh"></Mechanism>
            </a-form-model-item>
          </a-col>
        </a-row>
      </a-form-model>
    </j-form-container>
  </a-spin>
</template>

<script>

  import { httpAction, getAction } from '@/api/manage'
  import { validateDuplicateValue } from '@/utils/util'
  import Mechanism from '@/components/Mechanism'

  export default {
    name: 'CkbxCdLicaifinancingInfForm',
    components: {
      Mechanism
    },
    props: {
      //表单禁用
      disabled: {
        type: Boolean,
        default: false,
        required: false
      }
    },
    data () {
      return {
        model:{
         },
        labelCol: {
          xs: { span: 24 },
          sm: { span: 7 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 14 },
        },
        confirmLoading: false,
        validatorRules: {
          sjrq: [
            { required: true, message: '请选择数据日期!'},
          ],
          zgjhmc: [
            { required: true, message: '请输入资管计划名称!'},
          ],
          zclb: [
            { required: true, message: '请输入资产类别!'},
          ],
          zcmc: [
            { required: true, message: '请输入资产名称!'},
          ],
          zcbh: [
            { required: true, message: '请输入资产编码（或合同号）!'},
          ],
          zcyz: [
            { required: true, message: '请输入资产原值!'},
          ],
          zcjz: [
            { required: true, message: '请输入资产净值（或资产估值）!'},
          ],
        },
        url: {
          add: "/cdLicaifinancingInf/ckbxCdLicaifinancingInf/add",
          edit: "/cdLicaifinancingInf/ckbxCdLicaifinancingInf/edit",
          queryById: "/cdLicaifinancingInf/ckbxCdLicaifinancingInf/queryById"
        }
      }
    },
    computed: {
      formDisabled(){
        return this.disabled
      },
    },
    created () {
       //备份model原始值
      this.modelDefault = JSON.parse(JSON.stringify(this.model));
    },
    methods: {
      add () {
        this.edit(this.modelDefault);
      },
      edit (record) {
        this.model = Object.assign({}, record);
        this.visible = true;
      },
      submitForm () {
        const that = this;
        // 触发表单验证
        this.$refs.form.validate(valid => {
          if (valid) {
            that.confirmLoading = true;
            let httpurl = '';
            let method = '';
            if(!this.model.id){
              httpurl+=this.url.add;
              method = 'post';
            }else{
              httpurl+=this.url.edit;
               method = 'put';
            }
            httpAction(httpurl,this.model,method).then((res)=>{
              if(res.success){
                that.$message.success(res.message);
                that.$emit('ok');
              }else{
                that.$message.warning(res.message);
              }
            }).finally(() => {
              that.confirmLoading = false;
            })
          }
         
        })
      },
    }
  }
</script>